﻿<UserControl
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  xmlns:resx="clr-namespace:MyMedia_App.Properties"
  mc:Ignorable="d"
  x:Class="MyMedia_App.TimeControl"
  x:ClassModifier="internal"
  d:DesignWidth="250" d:DesignHeight="16">

  <UserControl.Resources>
    <LinearGradientBrush x:Key="TrackBackground" EndPoint="0,1" StartPoint="0,0">
      <GradientStop Color="#FF9C9D81" Offset="0.352"/>
      <GradientStop Color="#FFC6C7B5" Offset="0.88"/>
    </LinearGradientBrush>
    <LinearGradientBrush x:Key="DecreaseBackground" EndPoint="0,1" StartPoint="0,0">
      <GradientStop Color="#FFA5A99D" Offset="0.136"/>
      <GradientStop Color="#FF636552" Offset="0.916"/>
    </LinearGradientBrush>
    <LinearGradientBrush x:Key="TrackBorder" EndPoint="0,1" StartPoint="0,0">
      <GradientStop Color="#FF7B7D63" Offset="0.16"/>
      <GradientStop Color="#FFADAE94" Offset="1"/>
    </LinearGradientBrush>
    <Style x:Key="DecreaseRepeatButtonStyle" TargetType="{x:Type RepeatButton}">
      <Setter Property="OverridesDefaultStyle" Value="true"/>
      <Setter Property="IsTabStop" Value="false"/>
      <Setter Property="Focusable" Value="false"/>
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="{x:Type RepeatButton}">
            <Border CornerRadius="2.5,0,0,2.5" Background="{StaticResource DecreaseBackground}" Margin="6.5,1.5,0,1.3">
              <Rectangle Fill="Transparent" />
            </Border>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>
    <Style x:Key="IncreaseRepeatButtonStyle" TargetType="{x:Type RepeatButton}">
      <Setter Property="OverridesDefaultStyle" Value="true"/>
      <Setter Property="IsTabStop" Value="false"/>
      <Setter Property="Focusable" Value="false"/>
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="{x:Type RepeatButton}">
            <Rectangle Fill="Transparent"/>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>
    <LinearGradientBrush x:Key="ThumbStrokeBrush" EndPoint="0.5,1" StartPoint="0.5,0" MappingMode="RelativeToBoundingBox">
      <GradientStop Color="#FFEAEBE2" Offset="0"/>
      <GradientStop Color="#FF7E805F" Offset="0.8"/>
    </LinearGradientBrush>
    <LinearGradientBrush x:Key="ThumbBrush" EndPoint="0.5,0" StartPoint="0.5,1" MappingMode="RelativeToBoundingBox">
      <LinearGradientBrush.RelativeTransform>
        <TransformGroup>
          <RotateTransform Angle="-17.802" CenterX="0.5" CenterY="0.5"/>
        </TransformGroup>
      </LinearGradientBrush.RelativeTransform>
      <GradientStop Color="#FFFFFFFF" Offset="0.984"/>
      <GradientStop Color="#FFFFFFFF" Offset="0.38"/>
    </LinearGradientBrush>
    <LinearGradientBrush x:Key="ThumbBrushOver" EndPoint="0.5,1" StartPoint="0.5,0" MappingMode="RelativeToBoundingBox">
      <LinearGradientBrush.RelativeTransform>
        <TransformGroup>
          <RotateTransform Angle="-17.802" CenterX="0.5" CenterY="0.5"/>
        </TransformGroup>
      </LinearGradientBrush.RelativeTransform>
      <GradientStop Color="#FF99B4D1" Offset="0.868"/>
      <GradientStop Color="White" Offset="0"/>
    </LinearGradientBrush>
    <LinearGradientBrush x:Key="ThumbBrushDragging" EndPoint="0.5,1" StartPoint="0.5,0" MappingMode="RelativeToBoundingBox">
      <LinearGradientBrush.RelativeTransform>
        <TransformGroup>
          <RotateTransform Angle="-17.802" CenterX="0.5" CenterY="0.5"/>
        </TransformGroup>
      </LinearGradientBrush.RelativeTransform>
      <GradientStop Color="#FFEBEBEB" Offset="0.28"/>
      <GradientStop Color="#FF626262" Offset="1"/>
    </LinearGradientBrush>
    <Style x:Key="ThumbStyle" TargetType="{x:Type Thumb}">
      <Setter Property="Focusable" Value="false"/>
      <Setter Property="OverridesDefaultStyle" Value="true"/>
      <Setter Property="Height" Value="7"/>
      <Setter Property="Width" Value="12"/>
      <Setter Property="Foreground" Value="Gray"/>
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="{x:Type Thumb}">
            <Path
              x:Name="ThumbBody" SnapsToDevicePixels="True"
              Stroke="{StaticResource ThumbStrokeBrush}"
              Fill="{StaticResource ThumbBrush}"
              Data="M1,3.5 5,-0.5 9,3.5 5,7.5z" />
            <ControlTemplate.Triggers>
              <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Fill" TargetName="ThumbBody" Value="{StaticResource ThumbBrushOver}"/>
              </Trigger>
              <Trigger Property="IsDragging" Value="True">
                <Setter Property="Fill" TargetName="ThumbBody" Value="{StaticResource ThumbBrushDragging}"/>
              </Trigger>
            </ControlTemplate.Triggers>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>

    <Style x:Key="TimeSliderStyle" TargetType="{x:Type Slider}">
      <Setter Property="Stylus.IsPressAndHoldEnabled" Value="false"/>
      <Setter Property="Background" Value="Transparent"/>
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="{x:Type Slider}">
            <Border SnapsToDevicePixels="true" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
              <Grid>
                <Grid.RowDefinitions>
                  <RowDefinition Height="7"/>
                </Grid.RowDefinitions>
                <Border
                  x:Name="TrackBackground" Margin="5,0" VerticalAlignment="center"
                  Height="7.0"
                  Background="{StaticResource TrackBackground}"
                  BorderBrush="{StaticResource TrackBorder}" BorderThickness="1" CornerRadius="3">
                </Border>
                <Track x:Name="PART_Track">
                  <Track.DecreaseRepeatButton>
                    <RepeatButton
                      Margin="0,0,-4,0"
                      Style="{StaticResource DecreaseRepeatButtonStyle}"
                      Command="{x:Static Slider.DecreaseLarge}"/>
                  </Track.DecreaseRepeatButton>
                  <Track.IncreaseRepeatButton>
                    <RepeatButton
                      Style="{StaticResource IncreaseRepeatButtonStyle}"
                      Command="{x:Static Slider.IncreaseLarge}"/>
                  </Track.IncreaseRepeatButton>
                  <Track.Thumb>
                    <Thumb x:Name="Thumb" Style="{DynamicResource ThumbStyle}"/>
                  </Track.Thumb>
                </Track>
              </Grid>
            </Border>
            <ControlTemplate.Triggers>
              <Trigger Property="IsKeyboardFocused" Value="true">
                <Setter Property="Foreground" TargetName="Thumb" Value="Blue"/>
              </Trigger>
            </ControlTemplate.Triggers>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>
  </UserControl.Resources>

  <Grid Height="13">
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="Auto" />
      <ColumnDefinition Width="39*" />
            <ColumnDefinition Width="175*" />
            <ColumnDefinition Width="Auto"/>
    </Grid.ColumnDefinitions>

    <TextBlock
      x:Name="minTime" Text="0:00" VerticalAlignment="Center" FontSize="9"  />

    <Slider
      x:Name="slider" Style="{DynamicResource TimeSliderStyle}"
      IsMoveToPointEnabled="True" VerticalAlignment="Center"
      Minimum="0" Maximum="{Binding CurrentTrack.Duration}"
      Value="{Binding PlayerPosition}"
      ToolTip="Play Position"
      Grid.Column="1" Focusable="False" Grid.ColumnSpan="2" Margin="0,2" SmallChange="1" />

    <TextBlock
      x:Name="maxTime" Text="0:00" VerticalAlignment="Center" FontSize="9" Grid.Column="3" />

  </Grid>
</UserControl>
